"""Copyright 2011 Thomas Anesta, Jonathan Brenner, Tyler Moylat, Rosa Tung, Sean Kim"""

"""

This file is part of Bubbles

Bubbles is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bubbles is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

"""
import sys, pygame
import BubblesConstants

NUM_OF_BACKGROUNDS = 18

class Map(object):
    def __init__(self):
        """initializes the map"""
        self.type = BubblesConstants.MAP_TYPE
        self.yvel = 3
        self.backgrounds = []
        self.rects = []
        for i in range(NUM_OF_BACKGROUNDS):
            self.backgrounds.append(pygame.image.load("gfx/Backgrounds/background%d.png"%(i+1)).convert())
        
        self.rects.append(self.backgrounds[0].get_rect())
        self.rects.append(self.backgrounds[0].get_rect()) #all the rects are the same
        self.rects[0].x = 0
        self.rects[0].y = 0
        self.rects[1].x = 0
        self.rects[1].y = -BubblesConstants.WINDOW_HEIGHT
        self.background_count = 1

    def update(self):
        """updates the map"""
        for i, rect in enumerate(self.rects):
            rect.move_ip(0, self.yvel)
        
        if self.rects[0].y >= BubblesConstants.WINDOW_HEIGHT: #if the rect moves off the screen, add the new one
            del self.rects[0]
            self.rects.append(self.backgrounds[0].get_rect())
            self.rects[1].x = 0
            self.rects[1].y = -BubblesConstants.WINDOW_HEIGHT
            if self.background_count != NUM_OF_BACKGROUNDS:
                self.background_count += 1
                
    def draw(self, screen):
        """draws the map"""
        screen.blit(self.backgrounds[self.background_count-1], self.rects[0])
        if self.background_count != NUM_OF_BACKGROUNDS:
            screen.blit(self.backgrounds[self.background_count], self.rects[1])
        else:
            screen.blit(self.backgrounds[self.background_count-1], self.rects[1])
    
    